<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .div {
            width: 300px;
            height: 40px;
            border: 1px solid pink;
            text-align: center;
            line-height: 40px;
        }
    </style>
</head>

<body>
<div class="div"></div>
<script>
    //得到时间的div
    var time = document.querySelector('.div');

    function getTime() {
        //得到当前系统的事件
        const date = new Date();
        //对得到的时分秒来进行处理
        let h = date.getHours();
        let m = date.getMinutes();
        let s = date.getSeconds();
        //进行处理
        h = h < 10 ? '0' + h : h;
        m = m < 10 ? '0' + m : m;
        s = s < 10 ? '0' + s : s;
        return `今天是${date.getFullYear()}年${date.getMonth() + 1}月${date.getDate()}日${h}时${m}分${s}秒`
    }

    time.innerHTML = getTime();

    //使用定时器来进行开启
    setInterval(function () {
        time.innerHTML = getTime();
    }, 1000)
</script>
</body>
</html>